const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({
  data: {
    lists:[],
    source:"",
    type:2,
    isloading:true
  },
  onLoad: function (options) {
    this.lists()
    if(options.parentid){
      app.globalData.parentid=options.parentid
    }
  },
  change(e){
    this.setData({
      type:e.currentTarget.dataset.index,
      lists:[],
    })
    this.lists()
  },
  lists(contentType){
    var data={
      type:3,
      contentType:this.data.type
    }
    Controller.LikeOrVisitList(data).then(res=>{
      if(res.data.baseData && res.data.baseData.list.length>0){
        this.setData({
          lists:res.data.baseData.list,
        })
      }
      this.setData({
        isloading:false
      })
    })
  },
  golink3(e){
    if(!wx.getStorageSync('logintoken')){
      app.ToLogin()
      return
    }
    var id=e.currentTarget.dataset.id;
    wx.navigateTo({
      url:"/pages/mall/detail?id="+id
    });
  },
  gocart(e){
    var data={
      goodsId:e.currentTarget.dataset.id,
      specs:e.currentTarget.dataset.specs,
      amount:1,
      type:1
    }
    Controller.addOrUpdate(data).then(res=>{
      wx.showToast({
        title:"加购成功"
      })
    })
   
  },

  golink1(e){
    var item=e.currentTarget.dataset.item;
    if(this.data.type==1){
      wx.navigateTo({
        url:"/pages/news/detail?id="+item.contentId
      });
    }else if(this.data.type==2){
      if(item.lessonId){
        wx.navigateTo({
          url:"/pages/videoDetails/videoDetails?id="+item.id
        });
      }else{
        wx.navigateTo({
          url:"/pages/news/detail?id="+item.contentId
        });
      }
    }else if(this.data.type==3){
      wx.navigateTo({
        url:"/pages/recipesDetails/recipesDetails?id="+item.contentId
      });
    }
  },
  golink2(e){
    var id=e.currentTarget.dataset.id;
    var type=e.currentTarget.dataset.type;
    wx.navigateTo({
      url:"/pages/recipesDetails/recipesDetails?id="+id
    });
  },
  onShareAppMessage: function (e) {
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
  onShareTimeline: function(res){
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
})